package com.hualan.sfzy.controller.content;


import com.hualan.sfzy.entity.content.FMClassify;
import com.hualan.sfzy.service.content.FMClassifyService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
    @RequestMapping("/fmclassify")
    public class FMClassifyController {
        @Autowired
        private FMClassifyService service;
        @PostMapping
        public Result add(@RequestBody FMClassify classify){
            return service.add(classify)>0?Result.success():Result.error();
        }
        @DeleteMapping("/{id}")
        public Result remove(@PathVariable("id") Integer id){
            return service.remove(id)>0?Result.success():Result.error();
        }
        @DeleteMapping
        public Result removeBatch( Integer[] ids){
            return  service.removeBatch(ids)>0?Result.success():Result.error();
        }
        @PutMapping
        public Result edit(@RequestBody FMClassify classify){
            return   service.edit(classify)>0?Result.success():Result.error();
        }
        @GetMapping("/{id}")
        public Result findById (@PathVariable("id") Integer id){
              FMClassify fmClassify= service.findById(id);
              return Result.success(fmClassify);
        }
        @GetMapping("/page")
        public Result findPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize, FMClassify classify){
            Map<String,Object>  map= service.findPage(pageNum,pageSize,classify);
            return Result.success(map);
        }
        @GetMapping
        public Result find(){
            List<FMClassify> list= service.find();
            return Result.success(list);
        }

    }



